﻿@model HQPad.Models.IQualityContainer

@{
    ViewBag.Title = "Edit Qualities";
    Layout = "~/Views/Shared/_ModalLayout.cshtml";
    List<HQPad.Models.Quality> qualities = (List<HQPad.Models.Quality>)ViewBag.QualityTypes;
    var skills = (List<HQPad.Models.QualitySkillItem>) ViewBag.SkillList;
    var sects = (List<HQPad.Models.QualitySectItem>)ViewBag.SectList;
    var schools = (List<HQPad.Models.QualitySchoolItem>)ViewBag.SchoolList;
}
<script src="@Url.Content("~/Scripts/jquery-ui-1.10.3.custom.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/global.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/quality.js")" type="text/javascript"></script>

<script type="text/javascript">
    $(document).ready(function () {

        $('.add-quality').quality({
            skillListSelector: '.skill-list',      // selector for skill list section
            sectListSelector: '.sect-list',       // selector for sect list section
            schoolListSelector: '.school-list',     // selector for school list section
            spellLevelSelector: '.spell-level-list',     // selector for spell level list section
            typeListSelector: '#qualityType',   // selector for bonus list.
            typeLookupData: [
                @for (int i = 0; i < qualities.Count; i++) {
                    var qual = qualities[i];

                    if (i > 0) {
                        @Html.Raw(",");
                    }

                    @Html.Raw("{ type: '" + qual.Type.ToString() + "', selector: '" + qual.Choice.ToString() + "'}")
                }
            ],
            quantitySelector: '.quantity-item'
        });

    });
</script>

<h1>Special qualities for @Html.Raw(Model.ItemName)</h1>
<div class="message-box"></div>

<section class="modal-content">
    <div class="quality-list">
        @using (Html.BeginForm("RemoveQuality", "Character", FormMethod.Post, new { @name = "addQualityForm", @id = "addQualityForm" }))
        {
            if (Model.Qualities == null || Model.Qualities.Count == 0)
            {
                <p>This item has no special qualities.</p>
            }
            else
            {
                <table >
                    <thead>
                        <tr>
                            <th>Quality</th>
                            <th>Quantity</th>
                            <th>Target</th>
                            <th></th>
                        </tr>
                    </thead>
                    <tbody>
                @foreach (var item in Model.Qualities)
                {
                        <tr>
                            <td>@Html.Raw(Enum.GetName(typeof(HQPad.Services.BonusTypes), item.Type))</td>
                            <td>@Html.Raw(item.Quantity.ToString())</td>
                            <td>@Html.Raw(item.Value)</td>
                            <td>@Html.ActionLink("remove", "RemoveQuality", new { id = item.Id, itemId = Model.Id }, new { @class = "remove-button"})</td>
                        </tr>
                }
                    </tbody>
                </table>
            }
        }    
    </div>
    <div class="add-quality form">
        @using (Html.BeginForm("AddQuality", "Character", FormMethod.Post, new { @name = "addQualityForm", @id = "addQualityForm" }))
        {
            <input type="hidden" id="itemId" name="itemId" value="@Html.Raw(Model != null ? Model.Id.ToString() : "")" />
            
            <div class="field-item">
                <div class="label"><label for="qualityType">Type:</label></div>
                @Html.DropDownList("bonusType", new SelectList(qualities, "Type", "Description"), new { id = "qualityType" })
            </div>
  
            <div class="field-item skill-list" style="display:none;">
                <div class="label"><label for="skillSlug">Skill:</label></div>
                @Html.DropDownList("skillSlug", new SelectList(skills, "Slug", "Name"), new { id = "skillSlug" })
            </div>
            
            <div class="field-item spell-level-list" style="display:none;">
                <div class="label"><label for="spellLevel">Spell level:</label></div>
                @Html.DropDownList("spellLevel", new SelectList(new int[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}), new { id = "spellLevel" })
            </div>
  
            <div class="field-item sect-list" style="display:none;">
                <div class="label"><label for="sectSlug">Sect:</label></div>
                @Html.DropDownList("sectSlug", new SelectList(sects, "Slug", "Name"), new { id = "sectSlug" })
            </div>
  
            <div class="field-item school-list" style="display:none;">
                <div class="label"><label for="schoolSlug">School:</label></div>
                @Html.DropDownList("schoolSlug", new SelectList(schools, "Slug", "Name"), new { id = "schoolSlug" })
            </div>
            
            <div class="field-item quantity-item">
                <div class="label"><label for="quantity">Quantity:</label></div>
                @Html.TextBox("quantity", 1, new { @class = "textbox textbox-narrow", id = "quantity" })
            </div>
            
            <input type="submit" value="Add quality" />
        }
    </div>
</section>